# 7.1.1
# input()这个函数，参数传入是提示用户输入的字符串
# 既然参数是字符串类型，那也可以是等于这个字符串的变量
# 既然可以用变量作为提示，那么也可以用追加字符串的方式给这个字符串  改名
"""
prompt = 'If you share your name, we can personalize the messages you see.'
# prompt += '\nWhat is your name?\n\t'
name = input(prompt)
print(f'\nHello, {name}')

prompt = "\nTell me something, and I will repeat it back to you."
prompt += "\nEnter 'quit' to end the program"
active = True
while active:
    message = input(prompt)
    if message == 'quit':
        active = False
    else:
        print(message)
"""

# 7.2.5
# continue的使用
# 如果执行到continue语句，将跳过continue 后的代码块，直接去判断循环的条件语句
"""
currentNumber = 0
while currentNumber < 10:
    currentNumber += 1
    if currentNumber % 2 == 0:
        continue
    print(currentNumber)
"""
# 7.2后的动手试一试
# 练习7.4
"""
prompt = 'You added a pizza with the following topping:'
message = input(prompt)
print(message)
prompt += "\nYou can enter 'quit' to end the program."

while message != 'quit':
    message = input(prompt)
    if message != 'quit':
        print(message)

"""

# 7.3.10
# 要对列表的元素遍历以后分别进行操作
# 如果要让 while循环 和 for循环等价，可以使用pop()方法
# 现在只通过改造while循环，使得两种循环相同
# 可以将列表作为判断循环结束的条件，
# 每次通过pop()方法拿列表中的最后一个元素 进而实现遍历
# 但是遍历完成后原列表中的元素被清空，剩下一个空链表作为循环判断的条件，就会结束循环
"""
unconfirmedUsers = ['alice', 'brain', 'candace']
confirmedUsers = []
while unconfirmedUsers:
    curUser = unconfirmedUsers.pop()
    print(f'Verifying user: {curUser.title()}')
    confirmedUsers.append(curUser)

"""
# 注意：对于for循环来说，
# 当直接通过in来取到的可迭代元素中的一个个对象时
# 是从列表的末尾拿到元素的，
# 可以把列表看作是一个 和栈一样的存取方式
# 先进入列表的放在栈底，后进入列表的元素会先出栈
"""
print("\nThe following users have been confirmed:")
for confirmedUser in confirmedUsers:
    print(confirmedUser.title())
"""
# 7.3.3
"""
responses = {}
pollingActive = True
while pollingActive:
    name = input("\nWhat is your name?")
    response = input("Which mountain would you like to climb someday?")
    responses[name] = response
    repeat = input("Would you like to let another person respond?(yes/no)")
    if repeat == 'no':
        pollingActive = False

print(responses)
"""

# 7.3后面的动手试一试
# 练习7.8
"""
sandwichOrders = ["big", "small", "medium", "cheese"]
finishedSandwiches = []
while sandwichOrders:
    sandwichOrder = sandwichOrders.pop()
    print(f"I made your {sandwichOrder} sandwich.")
    finishedSandwiches.append(f'{sandwichOrder} sandwich')

print(finishedSandwiches)
"""

# 练习7.9
# 对不同的方法的说明：
# 1、remove()方法是从列表元素种索引小的元素(或者说栈底)开始遍历，遍历到相同字符串删除这个元素
# 2、pop()方法
#    如果不传入任何参数，默认是从索引大的元素(或者说栈顶)开始遍历，返回的结果是栈顶元素
#    如果传入索引，则会按照指定位置返回元素
# 3、append()方法是将参数插到列表最后(或者说栈顶)，类似于尾插
# 4、insert()方法有两个参数，第一个参数是在列表中要插入的位置，第二个参数是要插入的内容
finishedSandwiches = []
sandwichOrders = ["pastrami", "small", "medium", "cheese", "pastrami", "pastrami"]
while 'pastrami' in sandwichOrders:
    sandwichOrders.remove("pastrami")
    print(sandwichOrders)
    sandwichOrder = sandwichOrders.pop(0)
    finishedSandwiches.append(f'{sandwichOrder} sandwich')

print(finishedSandwiches)

# 练习7.10
answers = {}
numOfPa = 0
while numOfPa < 4:
    name = input("\nWhat is your name?")
    answer = input("If you could visit one place in the world, where would you go?")
    answers[name] = answer
    numOfPa += 1

print(answers)
for key, value in answers.items():
    print(f'{key.title()} would like to go {value}.')
